package com.easyctrl.ldy.view;

import com.easyctrl.ldy.activity.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class WaitView extends RelativeLayout implements AnimationListener {

	private RotateAnimation rotate;
	private TextView view;

	public WaitView(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.wait_view_anim, this);
		view = (TextView) findViewById(R.id.viewAnim);
		rotate = new RotateAnimation(0, 720, RotateAnimation.RELATIVE_TO_SELF,
				0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);

		rotate.setDuration(2 * 1000);
		rotate.setInterpolator(new LinearInterpolator());
		rotate.setRepeatCount(-1);
		
		rotate.setAnimationListener(this);
		
		view.startAnimation(rotate);
	}


	public void startAnim() {
		this.setVisibility(View.VISIBLE);
		view.startAnimation(rotate);
	}

	public void stopAnim() {
		rotate.cancel();
		this.setVisibility(View.GONE);
	}


	@Override
	public void onAnimationStart(Animation animation) { 
		isStop = true;
	}


	@Override
	public void onAnimationEnd(Animation animation) { 
		isStop = true;
	}


	@Override
	public void onAnimationRepeat(Animation animation) { 
		isStop = true;
	}
	
	private boolean isStop;
	
	public boolean isStop(){
		return isStop;
	}
}
